package add;

import java.util.concurrent.CountDownLatch;

/**
 * @projectName: JUC
 * @package: add
 * @className: CountDownLatchDemo
 * @author: 冷环渊 doomwatcher
 * @description: TODO
 * @date: 2022/3/2 13:56
 * @version: 1.0
 */
//计数器
public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        //    总数是六
        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 1; i <= 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "go out");
                //数量-1
                countDownLatch.countDown();
            }, String.valueOf(i)).start();
        }
        //等待计数器归零
        countDownLatch.await();
        System.out.println("Close door");
    }
}
